import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'example' }
      }
    ]
  },
  {
    path: '/pic',
    component: Layout,
    redirect: '/pic/index',
    children: [
      {
        path: 'index',
        name: 'pic',
        component: () => import('@/views/pic/index'),
        meta: { title: 'Banner管理', icon: 'member' }
      },
    ]
  },
  {
    path: '/category',
    component: Layout,
    redirect: '/category/index',
    children: [
      {
        path: 'index',
        name: 'category',
        component: () => import('@/views/category/index'),
        meta: { title: '分类管理', icon: 'member' }
      },
    ]
  },
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/index',
    children: [
      {
        path: 'index',
        name: 'goods',
        component: () => import('@/views/goods/index'),
        meta: { title: '商品管理', icon: 'member' }
      },
    ]
  },
  // {
  //   path: '/recharge',
  //   component: Layout,
  //   redirect: '/recharge/index',
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'recharge',
  //       component: () => import('@/views/recharge/index'),
  //       meta: { title: '充值记录', icon: 'member' }
  //     }
  //   ]
  // },
  {
    path: '/feedback',
    component: Layout,
    redirect: '/feedback/index',
    children: [
      {
        path: 'index',
        name: 'feedback',
        component: () => import('@/views/feedback/index'),
        meta: { title: '反馈列表', icon: 'member' }
      }
    ]
  },
  {
    path: '/invoice',
    component: Layout,
    redirect: '/invoice/index',
    children: [
      {
        path: 'index',
        name: 'invoice',
        component: () => import('@/views/invoice/index'),
        meta: { title: '开票列表', icon: 'member' }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    children: [
      {
        path: 'index',
        name: 'order',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'member' }
      }
    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: '/member/index',
    children: [
      {
        path: 'index',
        name: 'member',
        component: () => import('@/views/member/index'),
        meta: { title: '会员管理', icon: 'member' }
      }
    ]
  },
  {
    path: '/staff',
    component: Layout,
    redirect: '/staff/index',
    children: [
      {
        path: 'index',
        name: 'staff',
        component: () => import('@/views/staff/index'),
        meta: { title: '骑手管理', icon: 'member' }
      }
    ]
  },
  {
    path: '/company',
    component: Layout,
    redirect: '/company/list',
    meta: { title: '企业管理', icon: 'member' },
    children: [
      {
        path: 'list',
        name: 'company',
        component: () => import('@/views/company/index'),
        meta: { title: '企业列表', icon: 'member' }
      },
      {
        path: 'account',
        name: 'companyAccount',
        component: () => import('@/views/customer/index'),
        meta: { title: '企业用户', icon: 'member' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
